package uk.co.jonlt.AndBus;

import org.w3c.dom.*;

import android.util.Log;
import java.util.ArrayList;

public class Stops {
	
	public ArrayList<Stop> stops;
	
	public Stops()
	{
		stops = new ArrayList<Stop>();
	}
	
	public void Load(String xml)
	{
		// XML node keys
		String KEY_ITEM  = "Table"; // parent node
		String KEY_ROUTE = "route";
		String KEY_BUS_STOP_CODE  = "bus_stop_code";
		String KEY_STOP_NAME = "stop_name";
		String KEY_DESTINATION = "destination";
		 
		XmlParser parser = new XmlParser();
		Document doc = parser.getDomElement(xml); // getting DOM element
		 
		NodeList nl = doc.getElementsByTagName(KEY_ITEM);
		
		Log.i("Stop","About to loop through stop nodes");
		
		for (int i = 0; i < nl.getLength(); i++) 
		{
			Element e = (Element) nl.item(i);
			String route = parser.getValue(e, KEY_ROUTE);
		    String bus_stop_code = parser.getValue(e, KEY_BUS_STOP_CODE); // cost child value
		    String stop_name = parser.getValue(e, KEY_STOP_NAME); // description child value
		    String destination = parser.getValue(e, KEY_DESTINATION);
		    
		    Stop stop = new Stop(route,stop_name,bus_stop_code,destination);
		    stops.add(stop);
		}
	}

}

